package org.moriraaca.google.interview;

public class StringReverser {
	public String simpleReverse(String s) {
		StringBuilder sb = new StringBuilder(s);
		return sb.reverse().toString();
	}

	public String iterativeReverse(String s) {
		StringBuilder sb = new StringBuilder();

		for (int i = s.length() - 1; i >= 0; i--) {
			sb.append(s.charAt(i));
		}

		return sb.toString();
	}

	public String recursiveReverse(String s) {
		return s.isEmpty() ? "" : new StringBuilder().append(s.charAt(s.length() - 1))
				.append(recursiveReverse(s.substring(0, s.length() - 1)))
				.toString();
	}
	
	public String reverseWithoutSB(String s) {
		char [] charTable = new char[s.length()];
		
		for (int i = 0; i < charTable.length; i++) {
			charTable[i] = s.charAt(s.length() - i - 1);
		}
		
		return new String(charTable);
	}
}
